package io.wit.config;

import cloud.dwz.auth.AuthInterceptor;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;

@Configuration
public class ResourcesConfig extends WebMvcConfigurerAdapter {

    @Override
    public void addResourceHandlers(final ResourceHandlerRegistry registry) {
        registry.addResourceHandler("/statics/**").addResourceLocations("classpath:/statics/");
        registry.addResourceHandler("/swagger/**").addResourceLocations("classpath:/swagger/");
        registry.addResourceHandler("/mobile/**").addResourceLocations("classpath:/mobile/");
    }

    //静态资源配置2,优先级比 implements HandlerInterceptor 和 extends HandlerInterceptorAdapter
    @Override
    public void addInterceptors(final InterceptorRegistry registry){
        final String[] array = {"/error","","/","/index","/login","/user/login","/*.html","/statics/*.ico","/css/**","/statics/**","/mobile/**","/images/**","/js/**","/webjars/**","/swagger/**","/v2/api-docs","/swagger-ui.html","/swagger-resources/**","/v1.0/**","/v2/**"};
        //权限拦截器
        registry.addInterceptor(new AuthInterceptor()).addPathPatterns("/**").excludePathPatterns(array);
    }
}